package com.guigu.utils;

import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class FileUploadUtils {

    public static String rename(String fileName) {
    	// 获取后缀，加到新的文件名后面
        String extension = FilenameUtils.getExtension(fileName);
        return UUID.randomUUID().toString() + "." + extension;
    }

    public static String makeUploadDirectory(String parent, String fileName) {
        int hCode = fileName.hashCode();
        String hex = Integer.toHexString(hCode);
        return parent + File.separator + hex.charAt(0)+"/"+hex.charAt(1);
    }
    
/*    public static String makeUploadDirectoryByDate(String parent) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    	String dateStr = sdf.format(new Date());
        return parent + File.separator  + dateStr;
    }*/

    public static String makeUploadDirectoryByDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/");
        String dateStr = sdf.format(new Date());
        return dateStr;
    }
}
